package example.oauth;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

public class ConsumerProperties {
	
	
	public ConsumerProperties(String name,ClassLoader loader) throws IOException{
		this(getProperties(getResource(name, loader)));
	}
	public ConsumerProperties(Properties properties){
		this.consumerProperties = properties;
	}
	
	private final Properties consumerProperties;
	
	//protected OAuthConsumer newConsumer(String name){}
	
	public Properties getProperties(){
		return this.consumerProperties;
	}
	
	
	
	
	public static URL getResource(String name,ClassLoader loader) throws IOException{
		//URL resource = loader.getResource(name);
		URL resource = new URL(name);
		if(null == resource){
			throw new IOException("文件找不到:"+name);
		}
		return resource;
	}
	
	public static Properties getProperties(URL source) throws IOException{
		InputStream in = source.openStream();
		try {
			Properties p = new Properties();
			p.load(in);
			return p;
		}finally{
			in.close();
		}
	}
	
	public static void main(String[] arg){
		System.out.println(OAuth.class.getClassLoader().getResource("consumer.properties"));
		///ConsumerProperties coms = new ConsumerProperties("consumer.properties", .getClassLoader());
		//String p = coms.getProperties().getProperty("REQUEST_TOKEN_URL");
		//System.out.println(p);
	}
	
	
	
	
	
	
	
	
}
